#include <arpa/inet.h>
#include <csignal>
#include <iostream>
#include <unistd.h>

#include <singleton_delegator.h>

#include "my_socket_server.h"
#include "service_registry.h"
#include "prime_generator_service.h"

constexpr uint32_t SERVER_PORT = 55555;

void signalHandler(int signum)
{
    std::cout << "stoping" << std::endl;
    SingletonContainer::Get<MySocketServer>()->Stop();
}

int main(int argc,char *argv[])
{
    signal(SIGINT, signalHandler);

    sptr<IService> service = SingletonContainer::Get<PrimeGeneratorService>().GetRefPtr();
    SingletonContainer::Get<ServiceRegistry>()->AddService(service);

    std::cout << SingletonContainer::Get<MySocketServer>()->Start(SERVER_PORT) << ": " << errno << std::endl;
    SingletonContainer::Get<MySocketServer>()->Run();
    return 0;
}
